unit uListaPlanos;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  cxStyles, dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinscxPCPainter, cxCustomData, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, dxSkinsdxBarPainter,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ZAbstractRODataset,
  ZAbstractDataset, ZAbstractTable, ZDataset, dxBar, cxClasses, ActnList,
  ImgList, cxGridLevel, cxGridCustomView, cxGrid, StdCtrls, ExtCtrls,
   uCadastroPlanos, uCadastroGenerico;

type
  TfListaPlanos = class(TForm)
    pnl1: TPanel;
    lbl37: TLabel;
    pnlLeft: TPanel;
    gbList: TGroupBox;
    cxgrdCliente: TcxGrid;
    gdPlanos: TcxGridDBTableView;
    cxgrdlvlcliente: TcxGridLevel;
    ImageList: TImageList;
    ActionList: TActionList;
    actAdicionar: TAction;
    actEditar: TAction;
    actRemover: TAction;
    actGravar: TAction;
    actDesfazer: TAction;
    actAjuda: TAction;
    actRelatorio: TAction;
    actDSPrimeiro: TAction;
    actDSAnterior: TAction;
    actDSProximo: TAction;
    actDSUltimo: TAction;
    actDSBuscar: TAction;
    dxBarManager: TdxBarManager;
    dxBarManagerBar2: TdxBar;
    dxBarLargeButton1: TdxBarLargeButton;
    dxBarLargeButton2: TdxBarLargeButton;
    dxBarLargeButton3: TdxBarLargeButton;
    dxBarSubItem1: TdxBarSubItem;
    btnAdicionar: TdxBarLargeButton;
    btnEditar: TdxBarLargeButton;
    btnRemover: TdxBarLargeButton;
    btnGravar: TdxBarLargeButton;
    btnDesfazer: TdxBarLargeButton;
    tblPlanos: TZTable;
    dsPlanos: TDataSource;
    colPlanoscod_Plano: TcxGridDBColumn;
    colPlanosnomeplano: TcxGridDBColumn;
    colPlanosvalor_mensal: TcxGridDBColumn;
    colPlanosqtd_Dependente: TcxGridDBColumn;
    colPlanosacr_dependente: TcxGridDBColumn;
    colPlanosacr_idade: TcxGridDBColumn;
    colPlanosduracao: TcxGridDBColumn;
    colPlanoscarencia: TcxGridDBColumn;
    colPlanosvalor_total: TcxGridDBColumn;
    tblPlanoscod_plano: TIntegerField;
    tblPlanosnomeplano: TWideStringField;
    tblPlanosvalor_mensal: TFloatField;
    tblPlanosqtd_dependente: TIntegerField;
    tblPlanosacr_dependente: TFloatField;
    tblPlanosacr_idade: TFloatField;
    tblPlanosduracao: TIntegerField;
    tblPlanoscarencia: TIntegerField;
    tblPlanosvalor_total: TFloatField;
    procedure actAdicionarExecute(Sender: TObject);
    procedure actEditarExecute(Sender: TObject);
    procedure actRemoverExecute(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fListaPlanos: TfListaPlanos;

implementation

uses uDataModule;

{$R *.dfm}

procedure TfListaPlanos.actAdicionarExecute(Sender: TObject);
var
  aFCadastro: TfCadastroPlanos;
begin
  try
    aFCadastro:= TfCadastroPlanos.Criar('planos','seqplanos');
    aFCadastro.Modo := MCInsereVARIOS;
    aFCadastro.ShowModal;
  finally
    tblPlanos.Refresh;
    aFCadastro.Free;
  end;
end;

procedure TfListaPlanos.actEditarExecute(Sender: TObject);
var
  aFCadastro: TfCadastroPlanos;
begin
  try
    aFCadastro:= TfCadastroPlanos.Criar('planos','seqplanos');
    aFCadastro.Modo := MCEdita;
    aFCadastro.IdRegistro := tblPlanos.Fields[0].AsInteger;
    aFCadastro.ShowModal;
  finally
    tblPlanos.Refresh;
    aFCadastro.Free;
  end;
end;

procedure TfListaPlanos.actRemoverExecute(Sender: TObject);
begin
  if (MessageDlg('Deseja excluir o registro selecionado?', mtWarning, [mbYes, mbNo], 0) = mrYes) then
  begin
    DataModule1.RegisterEvent('Excluiu Plano',tblPlanoscod_plano.AsString+ ' - '+ tblPlanosnomeplano.Value);
    tblPlanos.Delete;
    tblPlanos.ApplyUpdates;
  end;

end;

end.
